package com.cy.pj.sys.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.common.web.pojo.JsonResult;
import com.cy.pj.sys.pojo.CGBNotice;
import com.cy.pj.sys.service.CGBNoticeService;
import com.fasterxml.jackson.core.JsonToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notice/")
public class CGBNoticeController {
    @Autowired
    private CGBNoticeService cgbNoticeService;

    @PostMapping
    public JsonResult doSaveNotice(@RequestBody CGBNotice cgbNotice){
        cgbNoticeService.insertNotice(cgbNotice);
        return new JsonResult("save ok");
    }


    @PutMapping
    public JsonResult doUpdateNotice(@RequestBody CGBNotice cgbNotice){
        cgbNoticeService.updateNotice(cgbNotice);
        return new JsonResult("update ok");
    }

    @DeleteMapping("{id}")
    public JsonResult doDeleteNotice(@PathVariable Integer id){
        cgbNoticeService.deleteNotice(id);
        return new JsonResult("delete ok");
    }


    @GetMapping
    public JsonResult doSelectNotice(CGBNotice cgbNotice){
        return new JsonResult(PageUtil.startPage()
        .doSelectPageInfo(()->{
            cgbNoticeService.selectByCondition(cgbNotice);
        }));
    }

    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(cgbNoticeService.selectById(id));
    }

}
